<template>
  <div class="person">
    <h1>情况一：监视【ref】定义的【基本类型】数据</h1>
    <h2>当前求和为:{{ sum }}</h2>
    <button @click="changeSum">点我sum+1</button>
  </div>
</template>

<script setup lang="ts" name="Person">
  import { ref, watch } from "vue";
  let sum = ref(0)

  function changeSum() {
    sum.value += 1
  }

  //监视
  const stopWatch = watch(sum, (newVal, oleVal) => {
    console.log('sum变化了', newVal, oleVal);
    //结束监视
    if (newVal >= 10) {
      stopWatch()
    }
  })

</script>
<style scoped>
  .person {
    width: 100%;
    background-color: skyblue;
    box-shadow: 0px 1px 2px #ddd;
    border-radius: 10px;
    padding: 20px;
  }

  button {
    margin: 0 5px;
  }

  li {
    font-size: 20px;
  }
</style>
